export default class playe extends Laya.Script {

    constructor() { 
        super(); 
        /** @prop {name:zidan, tips:"整数类型示例", type:prefab, default:null}*/
        this.zidan=null;
        
        this.GameOver=false;
        // 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0
    }
    onAwake(){
        console.log(stage);
        Laya.stage.on("GameOver",this,function(){this.GameOver=true;});
        Laya.stage.on("StartPlay",this,function(){this.GameOver=false;});
        this.rig=this.owner.getComponent(Laya.RigidBody);
        Laya.stage.on(Laya.Event.MOUSE_DOWN,this,this.pingmuClick);
        Laya.stage.on(Laya.Event.MOUSE_UP,this,this.taiqiClick);
        Laya.timer.loop(500,this,function(){
            this.Fire();
            this.Fire1();
        })
    }
    pingmuClick(){
        if(this.GameOver)return;
        var X=Laya.stage.mouseX;
        var score=0;

        if(X<Laya.stage.width/2){
            score=-1;
        }else{
            score=1;
        }
        this.rig.linearVelocity={x:score*25,y:0};
        Laya.Tween.to(this.owner,{rotation:score*25},300)
    }
    taiqiClick(){
        this.rig.linearVelocity={x:0,y:0};
        Laya.Tween.to(this.owner,{rotation:0},300);
    }
    Fire(){
        Laya.SoundManager.playSound("res/Sounds/fire.WAV",1);
        var zidanPanel=this.zidan.create();
        Laya.stage.getChildAt(0).getChildAt(0).addChild(zidanPanel)
        var zhidanX=this.owner.x;
        var zhidanY=this.owner.y;
        zidanPanel.pos(zhidanX-71,zhidanY-100);
    }
    Fire1(){
        Laya.SoundManager.playSound("res/Sounds/fire.WAV",1);
        var zidanPanel=this.zidan.create();
        Laya.stage.getChildAt(0).getChildAt(0).addChild(zidanPanel)
        var zhidanX=this.owner.x;
        var zhidanY=this.owner.y;
        zidanPanel.pos(zhidanX+71,zhidanY-100);
    }
    onTriggerExit(other){
        if(other.label=="jing"){
            this.score+=this.score;
        }
        if(other.label=="di"){
            Laya.SoundManager.playSound("res/Sounds/gameover.mp3",1);
            Laya.stage.event("GameOver");
        }
    }

}